package com.union.vehicleassistant.action;

import android.content.Context;

import androidx.annotation.StringRes;

import com.hjq.base.BaseDialog;
import com.union.vehicleassistant.util.callback.SimpleListener;
import com.union.vehicleassistant.widget.dialog.MessageDialog;

public interface DialogAction {

    default void messageDialog(Context context, String message, SimpleListener callback) {
        messageDialog(context, message, false, callback);
    }

    default void messageDialog(Context context, String message, boolean autoDismiss, SimpleListener callback) {
        new MessageDialog.Builder(context)
                .setMessage(message)
                .setListener(new MessageDialog.OnListener() {
                    @Override
                    public void onConfirm(BaseDialog dialog) {
                        if (callback != null) {
                            callback.onResult();
                        }
                    }

                    @Override
                    public void onCancel(BaseDialog dialog) {
                        if (callback != null) {
                            callback.onCancel();
                        }
                    }
                })
                .show();
    }

    default void messageDialog(Context context, @StringRes int message, SimpleListener callback) {
        messageDialog(context, message, false, callback);
    }

    default void messageDialog(Context context, @StringRes int message, boolean autoDismiss, SimpleListener callback) {
        String content = context.getResources().getString(message);
        messageDialog(context, content, autoDismiss, callback);
    }
}
